package mapper;

import pojo.Person;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface PersonMapper {
    @Select("select * from person where id = #{id} limit 1")
    Person selectById(int id);

    @Update("drop table if exists person")
    Integer dropTable();

    @Update("CREATE TABLE IF NOT EXISTS `person` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,`name` TEXT,`age` INTEGER)")
    Integer createTable();

    @Select("select * from person")
    List<Person> selectAll();

    @Delete("delete from person where id = #{id}")
    Integer deleteById(int id);

    @Insert("insert into person (name, age) values (#{name}, #{age})")
    Integer insert(Person model);

    @Update("update person set name = #{name}, age = #{age} where id = #{id}")
    Integer update(Person model);

    /**
     * 多个参数给一个映射器方法: 多个参数的情况下，默认它们将会以 param
     * 加上它们在参数列表中的位置来命名，比如：#{param1}、#{param2}等。如果你想（在有多个参数时）自定义参数的名称，那么你可以在参数上使用 @Param("paramName")
     * 注解。
     * 
     * @param id
     * @param name
     * @return
     */

    @Select("select * from person where id = #{id} and name = #{name}")
    List<Person> select(@Param("id") int id, @Param("name") String name);

    @Select("select * from person where id = #{param1} and name = #{param2}")
    List<Person> select1(int id, String name, int age);
}